import { createSSRApp } from "vue";
import { createPinia } from 'pinia'
import InterceptorRegisterCenter from './common/interceptor/Interceptor';
import App from "./App.vue";
import { EventConst, StorageConst } from '@/common/constants/index'

const app = createSSRApp(App);
const pinia = createPinia();
const isuse = uni.getStorageSync(StorageConst.ISUSE);
const url = isuse ? "pages/index/index" : "pages/splash/splash";

app.use(pinia);

// 注册拦截器
new InterceptorRegisterCenter();
// 重定向首页 网页调试时没有router会报错 
// #ifdef APP-PLUS
// 如果是已使用过App的用户这里并不需要再次进行启动页程序会自动加载首页并不需要重定向
!isuse && uni.navigateTo({animationType: "none", url, success() {
  // 跳转太快会导致闪屏 加个延时
  plus.navigator.closeSplashscreen();
  uni.setStorageSync(StorageConst.ISUSE, true);
} });

// 监听首页数据渲染完毕关闭启动页
uni.$once(EventConst.HOME_RENDERED, () => {
  plus.navigator.closeSplashscreen();
});

// 预加载tab模块
uni.preloadPage({url: "pages/classify/classify"});
uni.preloadPage({url: "pages/shopping-cart/shopping-cart"});
uni.preloadPage({url: "pages/personal/personal"});

// #endif

// 导出App
export function createApp() {
  return {
    app
  }
}